import pygame
import sys
from gameworld import GW
from game_event_manager import GameEventManager

class Tetris:
    def __init__(self):
        self.go_list = []

        pygame.init()
        self.screen = pygame.display.set_mode((800, 600))

    def run(self):
        clock = pygame.time.Clock()
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
                    break

            key_pressed = pygame.key.get_pressed()

            # --------------- update  ---------------
            for go in self.go_list:
                if hasattr(go, "update"):
                    go.update(key_pressed)

            # --------------- handler custom event ---------------
            GameEventManager.dispatch_event()

            # --------------- draw  ---------------
            self.screen.fill((255, 255, 255))

            for go in self.go_list:
                if hasattr(go, "draw"):
                    go.draw(self.screen)


            pygame.display.flip()
            # --------------- cock  ---------------
            clock.tick(60)

        pygame.quit()
        sys.exit()


